module Classes {

    export class Drop extends BaseObject {

        public shootType: number;
        public food: number;

        public lifeTime: number;
        public time: number;    // create time

        constructor() {
            super();

            this.shootType = 0;
            this.food = 0;

            this.lifeTime = 1000;
            this.time = new Date().valueOf();
        }

        public config(type: string): void {
            super.config(type, "independent");

            this.lifeTime = BaseObject.config[this.type].lifeTime || 1000;
            switch (this.type) {
                case "drop_food":
                    this.food = BaseObject.config[this.type].food;
                break;
                case "drop_weapon":
                    this.shootType = BaseObject.config[this.type].shootType;
                break;
            }

            this.body.on("complete", this, this.onComplete);
        }

        public onLoop(): void {
            this.y += this.speed;
        }

        public isAlive(): boolean{
            return (new Date().valueOf() - this.time <= this.lifeTime) && super.isAlive();
        }

        public pickedUpBy(player: Player): void {
            switch (this.type) {
                case "drop_food":
                    player.looseBlood(-this.food);
                break;
                case "drop_weapon":
                    player.changeShootType(this.shootType);
                    Laya.timer.once(BaseObject.config[this.type].bufTime, player, player.changeShootType, [1]);
                break;
            }
        }
        
    }

}